package com.jianbing.lakk.controller;

import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.jianbing.common.annotation.Log;
import com.jianbing.common.core.controller.BaseController;
import com.jianbing.common.core.domain.AjaxResult;
import com.jianbing.common.enums.BusinessType;
import com.jianbing.lakk.domain.LakkQuestionbank;
import com.jianbing.lakk.service.ILakkQuestionbankService;
import com.jianbing.common.utils.poi.ExcelUtil;
import com.jianbing.common.core.page.TableDataInfo;

/**
 * lakk_tikuController
 *
 * @author windbless
 * @date 2024-06-25
 */
@RestController
@RequestMapping("/lakk/QuestionBank")
public class LakkQuestionbankController extends BaseController {
    @Autowired
    private ILakkQuestionbankService lakkQuestionbankService;

    /**
     * 查询lakk_tiku列表
     */
//    @PreAuthorize("@ss.hasPermi('lakk:QuestionBank:list')")
    @GetMapping("/list")
    public TableDataInfo list(LakkQuestionbank lakkQuestionbank) {
        startPage();
        List<LakkQuestionbank> list = lakkQuestionbankService.selectLakkQuestionbankList(lakkQuestionbank);
        //遍历list
        for (LakkQuestionbank lakkQuestionbank1 : list) {
            if (lakkQuestionbank1.getQuestiontype().equals("拼图游戏")) {
                String str = lakkQuestionbank1.getCorrectanswer();
                String[] split = str.split(",");
                String yuantu = split[0];
                String[] split1 = yuantu.split("/");
                String temp = split1[6].split("_tile")[0];
                String needImg = "/" + split1[1] + "/" + split1[2] + "/" + split1[3] + "/" + temp + ".jpg";
                lakkQuestionbank1.setRewardrules(needImg);
            }
        }
        return getDataTable(list);
    }

    /**
     * 导出lakk_tiku列表
     */
//    @PreAuthorize("@ss.hasPermi('lakk:QuestionBank:export')")
    @Log(title = "lakk_tiku", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LakkQuestionbank lakkQuestionbank) {
        List<LakkQuestionbank> list = lakkQuestionbankService.selectLakkQuestionbankList(lakkQuestionbank);
        ExcelUtil<LakkQuestionbank> util = new ExcelUtil<LakkQuestionbank>(LakkQuestionbank.class);
        util.exportExcel(response, list, "lakk_tiku数据");
    }

    /**
     * 获取lakk_tiku详细信息
     */
//    @PreAuthorize("@ss.hasPermi('lakk:QuestionBank:query')")
    @GetMapping(value = "/{questionnumber}")
    public AjaxResult getInfo(@PathVariable("questionnumber") Long questionnumber) {
        return success(lakkQuestionbankService.selectLakkQuestionbankByQuestionnumber(questionnumber));
    }

    /**
     * 新增lakk_tiku
     */
//    @PreAuthorize("@ss.hasPermi('lakk:QuestionBank:add')")
    @Log(title = "lakk_tiku", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LakkQuestionbank lakkQuestionbank) {
        return toAjax(lakkQuestionbankService.insertLakkQuestionbank(lakkQuestionbank));
    }

    /**
     * 修改lakk_tiku
     */
//    @PreAuthorize("@ss.hasPermi('lakk:QuestionBank:edit')")
    @Log(title = "lakk_tiku", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LakkQuestionbank lakkQuestionbank) {
        return toAjax(lakkQuestionbankService.updateLakkQuestionbank(lakkQuestionbank));
    }

    /**
     * 删除lakk_tiku
     */
//    @PreAuthorize("@ss.hasPermi('lakk:QuestionBank:remove')")
    @Log(title = "lakk_tiku", businessType = BusinessType.DELETE)
    @DeleteMapping("/{questionnumbers}")
    public AjaxResult remove(@PathVariable Long[] questionnumbers) {
        return toAjax(lakkQuestionbankService.deleteLakkQuestionbankByQuestionnumbers(questionnumbers));
    }
}
